package chixing.day11.prototype;

import java.util.Arrays;

public class OrderProcessSystem {
    public static void main(String[] args) {
        PersonalOrder personalOrder = new PersonalOrder(101, "aaa", 2400);
        Order[] process = process(personalOrder);
        for (Order o:process) {
            System.out.println(o);
        }

        EnterpriseOrder enterpriseOrder = new EnterpriseOrder(202, "xx企业", 2000);
        Order[] process1 = process(enterpriseOrder);
        for (Order o:process1) {
            System.out.println(o);
        }
    }


    public static Order[] process(Order order){
        int productNumber = order.getProductNumber();
        int subOrderCount = productNumber % 1000 ==0 ? (productNumber/1000):(productNumber/1000 + 1);
        Order[] suborderArr = new Order[subOrderCount];
        int suborderArrIndex = 0;
        while (productNumber > 1000){
            Order myclone = order.myclone();
            myclone.setProductNumber(1000);
            order.setProductNumber(productNumber-1000);
            productNumber-=1000;
            suborderArr[suborderArrIndex++]=myclone;
        }
        suborderArr[suborderArrIndex]=order;
        return suborderArr;
    }

}